import pandas as pd
from numpy import *
import FP_Grow_tree
import time

def prepare_data():
    df = pd.read_excel("./超市数据集.xls")
    prd_name = array(df.ix[0])

    data = df.iloc[1:,:].as_matrix()
    items_arr = []

    for i in range(0, len(data)):
        row = data[i]
        new_row = []
        for j in range(0, len(row)):
            if(row[j] == 'T'):
                new_row.append(prd_name[j])
        items_arr.append(new_row)
        
    data_set = list(map(set, items_arr))
    return data_set

data_set = prepare_data()

begin_time = time.time()
support = 200
ff=FP_Grow_tree.FP_Grow_tree(data_set,[],support)
end_time = time.time()
ff.printfrequent()
print("Elapsed Time:" + str((end_time - begin_time) * 1000) + " milliseconds")

